<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 将 object 对象中的 key 和 value 互换。 -->
</head>
<body>
  <script>
    let object = {
      name: '张三',
      age: 30,
      sex: '男'
    }
    for (let i in object) {
      let value = object[i]; //将原来的value赋值给一个变量
      object[value] = i; // 为object赋新key，不能直接使用object = {object[k] : k},会报语法错误
      delete object[i];// 删除原来的属性
    }
    console.log(object);
  </script>
</body>
</html>